/*
 * 1285. Power of Four
 * Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
 * https://www.lintcode.com/problem/power-of-four/description
 * 
 * 样例
 * Example1:
 * Given num = 16, 
 * return true.
 * 
 * Example2:
 * Given num = 5, 
 * return false.
 * 
 * 挑战
 * Could you solve it without loops/recursion?
 * 
 * 2018.06.12 @jeyming
 */
package power_of_four_1285;

public class Power_of_four_1285 {
    /**
     * @param num: an integer
     * @return: whether the integer is a power of 4
     */
    public boolean isPowerOfFour(int num) {
        // Write your code here
    	boolean judge = false;
    	while(num > 0) {
    		if(num == 1) {
    			judge = true;
    			break;
    		}
    		if((num % 4 != 0) && (num != 1)) {
    			break;
    		}
    		if((num % 4 == 0) && (num/4 == 1)) {
    			judge = true;
    		}
    		num /= 4;
    	}
        return judge;
    }

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
